package chat.ui;

import java.util.*;


import javax.swing.JEditorPane;
import javax.swing.JTextArea;

public class ChatHandler implements Runnable {
	
	private static String date, month, day, time, hour, mins;
	private String BOLD1="",BOLD2="";
	
	public ChatHandler(){
		
		new DateForMessages();
	}
	
	@Override
	public void run(){
		
	}
	
	public ChatPanel setTextFromMessageToGroup(String text, ChatPanel area, String destination_name, String from_name){
		
		if (area.bold.isSelected()) { BOLD1="<b>"; BOLD2="</b>";}
		else {BOLD1=""; BOLD2="";}
		if (area.italic.isSelected()) ; 
			
		if (area.underline.isSelected()) ;
		
		String new_text = "<font color='blue' size='4'><i>"
				+DateForMessages.getCurrentDateFromMessage()
				+"</i></font>"
				+" "
				+"<b><font color='green' size='4'>"
				+from_name
				+"</font></b>"
				+"<br/>"
				+BOLD1
				+text
				+BOLD2
				+"<br/>";
		
		 area.addContactMessage(new_text, destination_name);
		
		/*if (!t.equalsIgnoreCase("")){
				new_text = t + "\n" + "<font color='red' size='4'>"+DateForMessages.getCurrentDateFromMessage()+"</font>" +" "+"<b><font color='green' size='4'>"+from_name+"</font></b>"+ " "+text;
		}
		else {
			new_text = "<font color='red' size='4'>"+DateForMessages.getCurrentDateFromMessage()+"</font>" +" "+"<b><font color='green' size='4'>"+from_name+"</font></b>"+ " "+text;
		}*/
		
		/*JEditorPane p = new JEditorPane();
		p.setText(new_text);
		area.getScrollPanel().add(p);*/
		
		String mesBuffer = area.getContactMessages(destination_name);
		
		area.setChatText(mesBuffer, destination_name);
		
		return area; 
	}
	
	private static class DateForMessages {
		
		@SuppressWarnings("deprecation")
		public DateForMessages(){
			
			c_date = new Date();
			
			date_hour = c_date.getHours();
			date_minutes = c_date.getMinutes();
			
			date_year = 1900 + c_date.getYear();
			date_month = c_date.getMonth()+1;
			date_day = c_date.getDate();
			
			
		}
		
		public static String getCurrentDateFromMessage() {
			
			date1 = proceedDate(date_day)+"/"+proceedDate(date_month)+"/"+date_year+" "+proceedDate(date_hour)+":"+proceedDate(date_minutes);
			
			return date1;
		}
		
		private static String proceedDate(int param){
			
			String value = null;
			
			if (param<10){
				value = "0" + Integer.toString(param);
			} else {
				value = Integer.toString(param);
			}
			
			return value;
		}
		private static int date_hour, date_minutes, date_year, date_month, date_seconds, date_month_number, date_day;
		private static String date1;
		Date c_date;
	}
		
	 
}
